Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: introduce thiserror-ext for boxed error wrapper definition #13200

Merged
merged 4 commits into from
Nov 2, 2023

Conversation

BugenZhao
Copy link
Member

@BugenZhao BugenZhao commented Nov 1, 2023

I hereby agree to the terms of the RisingWave Labs, Inc. Contributor License Agreement.

What's changed and what's your intention?

As explained in #13215. Introducing the thiserror-ext proc-macros.

  • Box: Derive a new type wrapping the enum with Box. Automatically implement all Froms and forward error implementation.
  • Construct: Derive constructors on the new type.

This is a first attempt so I only refactor the udf::Error as a demo.

Will release the proc-macros on crates.io after it gets more stable.


Derived:

  • Box
/// The boxed type of [`ErrorInner`].
#[derive(thiserror_ext::__private::thiserror::Error, Debug)]
#[error(transparent)]
pub struct Error(
    #[from]
    #[backtrace]
    thiserror_ext::__private::ErrorBox<ErrorInner>,
);

impl<E> From<E> for Error
where
    E: Into<ErrorInner>,
{
    fn from(error: E) -> Self {
        Self(thiserror_ext::__private::ErrorBox::new(error.into()))
    }
}
impl Error {
    /// Returns the reference to the inner error.
    pub fn inner(&self) -> &ErrorInner {
        self.0.inner()
    }

    /// Consumes `self` and returns the inner error.
    pub fn into_inner(self) -> ErrorInner {
        self.0.into_inner()
    }
}
  • Construct
#[automatically_derived]
impl Error {
    /// Constructs a [`ErrorInner::TypeMismatch`] variant.
    pub fn type_mismatch(arg_0: impl Into<String>) -> Self {
        ErrorInner::TypeMismatch { 0: arg_0.into() }.into()
    }

    /// Constructs a [`ErrorInner::Unsupported`] variant.
    pub fn unsupported(arg_0: impl Into<String>) -> Self {
        ErrorInner::Unsupported { 0: arg_0.into() }.into()
    }

    /// Constructs a [`ErrorInner::NoReturned`] variant.
    pub fn no_returned() -> Self {
        ErrorInner::NoReturned {}.into()
    }

    /// Constructs a [`ErrorInner::ServiceError`] variant.
    pub fn service_error(arg_0: impl Into<String>) -> Self {
        ErrorInner::ServiceError { 0: arg_0.into() }.into()
    }
}

Checklist

  • I have written necessary rustdoc comments
  • I have added necessary unit tests and integration tests
  • All checks passed in ./risedev check (or alias, ./risedev c)

Documentation

  • My PR needs documentation updates. (Please use the Release note section below to summarize the impact on users)

Release note

If this PR includes changes that directly affect users or other significant modifications relevant to the community, kindly draft a release note to provide a concise summary of these changes. Please prioritize highlighting the impact these changes will have on users.

@BugenZhao BugenZhao changed the title refactor: introduce thiserror-ext for painless error definition refactor: introduce thiserror-ext for boxed error wrapper definition Nov 2, 2023
Signed-off-by: Bugen Zhao <[email protected]>
Signed-off-by: Bugen Zhao <[email protected]>
@BugenZhao BugenZhao marked this pull request as ready for review November 2, 2023 09:39
@BugenZhao BugenZhao requested a review from a team as a code owner November 2, 2023 09:39
Copy link
Contributor

@wangrunji0408 wangrunji0408 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

src/udf/src/error.rs Show resolved Hide resolved
src/udf/src/external.rs Show resolved Hide resolved
Copy link

codecov bot commented Nov 2, 2023

Codecov Report

Merging #13200 (6b03485) into main (6bd797e) will increase coverage by 0.00%.
Report is 8 commits behind head on main.
The diff coverage is 0.00%.

@@           Coverage Diff           @@
##             main   #13200   +/-   ##
=======================================
  Coverage   68.08%   68.08%           
=======================================
  Files        1512     1512           
  Lines      256245   256239    -6     
=======================================
+ Hits       174457   174458    +1     
+ Misses      81788    81781    -7     
Flag Coverage Δ
rust 68.08% <0.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
src/udf/src/external.rs 0.00% <ø> (ø)
src/expr/core/src/expr/expr_udf.rs 0.00% <0.00%> (ø)
src/expr/core/src/table_function/user_defined.rs 0.00% <0.00%> (ø)
src/udf/src/error.rs 0.00% <0.00%> (ø)

... and 5 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Member

@xxchan xxchan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a first attempt so I only refactor the udf::Error as a demo.

From the PR it's not crystal clear what's the benefit. And related issues are very long. Do you have a TLDR so that anyone can understand it easily? 😄

Specifically, how does this help improve user-facing err msg and/or DX?

@xxchan
Copy link
Member

xxchan commented Nov 2, 2023

Specifically, how does this help improve user-facing err msg and/or DX?

If this is not clear enough, it might be better to refactor a different error as the demo to show the power.

@BugenZhao
Copy link
Member Author

Do you have a TLDR so that anyone can understand it easily? 😄

Have you gone through #13215? I tried my best to explain the motivation on this. 🥺

@BugenZhao
Copy link
Member Author

Updated the expanded output in the PR body.

@xxchan
Copy link
Member

xxchan commented Nov 2, 2023

Do you have a TLDR so that anyone can understand it easily? 😄

Have you gone through #13215? I tried my best to explain the motivation on this. 🥺

Well, since you are talking about a “demo”, I hope this PR alone can be used to convince and guide others (any dev without enough patience to go through the whole story).🥹

If it’s just “part of” the work, I think it’s OK not too explain further.

Signed-off-by: Bugen Zhao <[email protected]>
@BugenZhao
Copy link
Member Author

If it’s just “part of” the work, I think it’s OK not too explain further.

Yeah. This PR is just for asking for your opinion. Will refactor more in next PRs.

@BugenZhao BugenZhao enabled auto-merge November 2, 2023 11:41
@BugenZhao BugenZhao added this pull request to the merge queue Nov 2, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Nov 2, 2023
@BugenZhao BugenZhao added this pull request to the merge queue Nov 2, 2023
Merged via the queue into main with commit c02cdc4 Nov 2, 2023
7 of 8 checks passed
@BugenZhao BugenZhao deleted the bz/thiserror-ext-first-attempt branch November 2, 2023 13:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants